﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UI.Models;
using Model;
using Repository;
using System.Net.Mail;
using System.Configuration;
using UI.Helper;

namespace UI.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ProductNewwest obj = new ProductNewwest();
            var repositoryProduct = RepositoryManager.CreateProductRepository();
            obj.liProduct = repositoryProduct.GetNewwest();

            return View(obj);
        }

        public ActionResult About()
        {
            var model = new ProductModel();

            return View(model);
        }

        public ActionResult Contact()
        {
            var model = new UserModel();

            return View(model);
        }

        public ActionResult Product()
        {
            var model = new UserModel();

            return View(model);
        }

        [HttpPost]
        public ActionResult SendEmail(UserModel objUserModel)
        {
            if (ModelState.IsValid)
            {

                //MailMessage mail = new MailMessage();
                //mail.To.Add(ConfigurationManager.AppSettings[TO_HCM_ADDRESS].ToString());
                //mail.From = new MailAddress(ConfigurationManager.AppSettings[FROM_ADDR].ToString());
                //mail.Subject = txtSubject.Text;
                //mail.Body = txtBody.Text + "\nCustomer email: " + txtStdEmail.Text;

                //mail.IsBodyHtml = true;
                //string username = ConfigurationManager.AppSettings[ACCOUNT].ToString();
                //string password = ConfigurationManager.AppSettings[PASSWORD].ToString();

                //SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings[SMTP_CLIENT].ToString());
                //smtp.Credentials = new System.Net.NetworkCredential(username, password);
                //smtp.EnableSsl = true;

                //smtp.Send(mail);
                var model = new UserModel();
                TempData[Constants.MESSAGE] = "Da gui mail";
                return RedirectToAction("Index", "Home");
            }

            //return with Error
            return View(objUserModel);
        }
    }
}
